import React, { useRef, useState, useEffect } from 'react';
import GoBack from "@/components/TheGoBack";
import { MinusCircleOutlined, PlusOutlined, ExclamationCircleFilled } from '@ant-design/icons';
import { useLocation, useNavigate } from 'react-router-dom';
import {
  ProForm,
  ProFormCheckbox, ProFormDatePicker,
  ProFormDateTimePicker,
  ProFormDateTimeRangePicker, ProFormDependency, ProFormDigit, ProFormGroup, ProFormList, ProFormMoney,
  ProFormSelect, ProFormSwitch,
  ProFormText
} from '@ant-design/pro-components';
import { Col, List, message, Modal, Row, Space, Form, InputNumber, Button } from "antd";
import moment from "moment";
import { apiGetActivityConfig, apiActivitySkuRepetitionVerify, apiActivitySkuFloorPriceVerify, apiPlatformActivitySheetAdd, apiPlatformActivitySheetView, apiPlatformActivitySheetEdit } from "@/api/activityManager/index.js";
import Goods from "./goods.jsx";
import TheUpload from "@/components/TheUpload/index.jsx";
import NoCanJoinGood from "./noCanJoinGood.jsx";
import { apiGetStoreInfo } from '@/api/couponManagement/couponsList.js'

const { confirm } = Modal;

const Add = () => {
  const navigate = useNavigate()
  const location = useLocation();
  const formRef = useRef();
  const PromotionsBox = useRef();
  const blackGoodsRef = useRef();
  const mode = location.state.mode;
  const activityId = location.state.activityId
  const [isProprietary, setIsProprietary] = useState()
  const [blackGoodsKey, setBlackGoodsKey] = useState([])
  const [checkIng, setCheckIng] = useState(false)
  const [goodsSku, setGoodsSku] = useState([])
  const [goodsFlag, setGoodsFlag] = useState(true)
  const [clashData, setClashData] = useState([])
  const [saveData, setSaveData] = useState({})
  const [visible, setVisible] = useState(false)
  const [couponsCopy, setCouponsCopy] = useState([])
  const [sights, setSights] = useState([])
  const [loading, setLoading] = useState(false)
  let title = null
  switch (mode) {
    case 'add':
      title = "创建活动";
      break;
    case 'edit':
      title = "编辑活动";
      break;
    case 'view':
      title = "活动详情";
      break;
    default:
      break;
  }

  const formItemLayout = {
    labelCol: { span: 3 },
    wrapperCol: { span: 18 },
  }

  useEffect(() => {
    getShopInfo()
  }, [])

  const getShopInfo = async () => {
    await apiGetStoreInfo().then(res => {
      if (res.code === 0) {
        setIsProprietary(res.data.isProprietary)
      }
    })
  }
  const disabledDate = current => {
    return current && current < moment().startOf('days');
  }
  const addGoods = (e) => {
    const { activityType } = formRef.current.getFieldsValue()
    let whiteKey = []
    e.goodsSku.forEach(item => {
      item[1].forEach(goods => {
        whiteKey.push(goods.goodsId)

        if (activityType === 'FULL_GIFT') {
          goods.skuInfoVos.forEach(ss => {
            if (ss.isJoinFlag) {
              ss.activityPrice = 0
            }
          })
        }
      })
    })
    setGoodsSku(e.goodsSku)
    // this.setState({
    //     whiteGoodsKey: whiteKey, goodsSku: e.goodsSku
    //
    // })
    formRef.current.setFieldsValue({
      goodsSku: e.goodsSku,
      checkIng: false,
    })
  }
  const onFinish = (values) => {
    return new Promise((resolve) => {
      let submitData = async (params) => {
        console.log(values.enableCommissionRate, params, 'ddddd');
        let result = await apiActivitySkuRepetitionVerify(params)
        // console.log(result);
        if (result.code === 0 && (result.data !== null && result.data.length > 0)) {
          // this.setState({
          //     clashData: result.data,
          //     visible: true,
          //     saveData: params
          // })
          setVisible(true)
          setSaveData({
            ...params,
            enableCommissionRate: values.enableCommissionRate,
            commissionRate: values.commissionRate
          })
          setClashData(result.data)
          setTimeout(() => {
            resolve(true);
          }, 1000)
        } else if (result.code === 0 && (result.data === null || result.data.length === 0)) {
          if (mode === "add") {
            let res = await apiPlatformActivitySheetAdd({
              ...params,
              enableCommissionRate: values.enableCommissionRate,
              commissionRate: values.commissionRate,
            })
            if (res.code === 0 && res.data) {
              // this.props.history.goBack(-1)
              navigate(-1)
            }
          } else {
            let res = await apiPlatformActivitySheetEdit({
              ...params,
              enableCommissionRate: values.enableCommissionRate,
              commissionRate: values.commissionRate,
            })
            if (res.code === 0 && res.data) {
              // this.props.history.goBack(-1)
              navigate(-1)
            }
          }
          setTimeout(() => {
            resolve(true);
          }, 1000)
        }
      }
      values.goodsSku = goodsSku
      let params = {}
      if (!goodsFlag) {       //未填写活动价格 一秒后取消提交loading
        setTimeout(() => {
          resolve(true);
        }, 1000)
      }
      if (mode === "add") {
        if (['SHOP_GOODS', 'NEW_COME', 'FULL_GIFT'].includes(values.activityType) && !goodsFlag) return
        let activityDetailVos = []
        if (['SHOP_GOODS', 'NEW_COME', 'FULL_GIFT'].includes(values.activityType)) {
          activityDetailVos = values.goodsSku ? values.goodsSku.map((item, activeIndex) => {
            return {
              activityGoodsVos: item[1].map((goods, ii) => {
                return {
                  activityGoodsSkuVos: goods.skuInfoVos.map(sku => {
                    sku.isJoinFlag = true
                    return {
                      "goodsId": goods.goodsId,
                      "goodsSkuId": sku.goodsSkuId,
                      "activityGoodsSkuPrice": !sku.isJoinFlag ? sku.skuCurrentPrice : sku.activityPrice === null ? sku.skuCurrentPrice : Number((Number(sku.activityPrice) * 100).toFixed(0)),
                      activityGoodsSkuOriginalPrice: sku.skuOriginalPrice,
                      currentPrice: sku.currentPrice,
                      activityGoodsSkuId: sku.activityGoodsSkuId,
                      activityGoodsId: sku.activityGoodsId,
                      skuAttributes: JSON.stringify(sku.skuAttributes),
                      aliasName: sku.aliasName,
                      skuEnabled: sku.isJoinFlag ? 1 : 0
                    }
                  }),
                  sort: ii + 1,
                  "goodsId": goods.goodsId,
                  storeId: goods.storeId
                }
              }),
              "activityDetailName": item[0],
              "prizeType": "goods",
              "activityName": values.activityName,
              sort: activeIndex + 1,
              thresholdPrice: values.activityType === 'FULL_GIFT' ? Number((Number(item[2]) * 100).toFixed(0)) : 0
            }
          }) : []
        } else if (['COUPONS'].includes(values.activityType)) {
          activityDetailVos = values.coupons.map((item, index) => {
            return {
              activityDetailName: item.couponTitle,
              "prizeType": item.couponType,
              sort: index + 1,
              prizeId: item.couponId,
            }
          })
        } else if (['FULL_REDUCTION'].includes(values.activityType)) {
          activityDetailVos = values.sights.map((item, index) => {
            return {
              sort: index + 1,
              "thresholdPrice": Number((Number(item.thresholdPrice) * 100).toFixed(0)),
              "discountPrice": Number((Number(item.discountPrice) * 100).toFixed(0)),
              prizeType: values.activityType
            }
          })
        }
        params = {
          // activityLabelImg: values.activityLabelImg,
          activityImg: values.activityImg,
          "activityName": values.activityName,
          "activityCount": -1, //活动数量 （ -1 为 无限量 ）
          "couponEnabled": values.couponEnabled === "1" ? 0 : 1, //能否使用优惠券 0 可以使用 1 不能使用
          "activityStatus": 1, //活动状态（0：正常 1：关闭）
          "activityType": values.activityType, //活动类型 （COUPONS 优惠卷 SHOP_GOODS 商城商品）
          activityDetailVos,
          activityLevel: values.activityLevel,
          detailExplain: values.detailExplain,
          detailImg: values.detailImg,
          startTime: values.startTime,
          endTime: values.endTime,
          timeType: values.timeType,
        }
      } else {
        if (['SHOP_GOODS', 'NEW_COME', 'FULL_GIFT'].includes(values.activityType) && !goodsFlag) return
        let activityDetailVos = []
        if (['SHOP_GOODS', 'NEW_COME', 'FULL_GIFT'].includes(values.activityType)) {
          activityDetailVos = values.goodsSku.map((item, activeIndex) => {
            return {
              activityDetailId: item[1].length > 0 ? item[4] : '',
              activityGoodsVos: item[1].map((goods, ii) => {
                return {
                  activityDetailId: item[1].length > 0 ? item[4] : '',
                  activityGoodsId: goods.activityGoodsId,
                  activityGoodsSkuVos: goods.skuInfoVos.map(sku => {
                    sku.isJoinFlag = true
                    return {
                      "goodsId": goods.goodsId,
                      "goodsSkuId": sku.goodsSkuId,
                      "activityGoodsSkuPrice": !sku.isJoinFlag ? sku.skuCurrentPrice : sku.activityPrice === null ? sku.skuCurrentPrice : Number((Number(sku.activityPrice) * 100).toFixed(0)),
                      currentPrice: sku.currentPrice,
                      activityGoodsSkuOriginalPrice: sku.skuOriginalPrice,
                      activityGoodsSkuId: sku.hasOwnProperty('activityGoodsSkuId') ? sku.activityGoodsSkuId : '',
                      activityGoodsId: sku.hasOwnProperty('activityGoodsId') ? sku.activityGoodsId : '',
                      skuAttributes: JSON.stringify(sku.skuAttributes),
                      aliasName: sku.aliasName,
                      skuEnabled: sku.isJoinFlag ? 1 : 0
                    }
                  }),
                  sort: ii + 1,
                  "goodsId": goods.goodsId,
                  storeId: goods.storeId
                }
              }),
              "activityDetailName": item[0],

              "prizeType": "goods",
              "activityName": values.activityName,
              sort: activeIndex + 1,
              thresholdPrice: values.activityType === 'FULL_GIFT' ? Number((Number(item[2]) * 100).toFixed(0)) : 0

            }
          })
        } else if (['COUPONS'].includes(values.activityType)) {
          activityDetailVos = values.coupons.map((item, index) => {
            const ii = couponsCopy.findIndex(ii => ii.couponId === item.couponId)
            return {
              activityDetailName: item.couponTitle,
              "prizeType": item.couponType,
              sort: index + 1,
              prizeId: item.couponId,
              activityDetailId: ii > -1 ? couponsCopy[ii].activityDetailId : '',

            }
          })
        } else if (['FULL_REDUCTION'].includes(values.activityType)) {
          activityDetailVos = values.sights.map((item, index) => {
            const ii = sights.findIndex(ii => (item.hasOwnProperty('activityDetailId') && ii.activityDetailId === item.activityDetailId))
            return {
              sort: index + 1,
              "thresholdPrice": Number((Number(item.thresholdPrice) * 100).toFixed(0)),
              "discountPrice": Number((Number(item.discountPrice) * 100).toFixed(0)),
              prizeType: values.activityType,
              activityDetailId: ii > -1 ? sights[ii].activityDetailId : null
            }
          })
        }
        params = {
          activityId: activityId,
          activityImg: values.activityImg,
          "activityName": values.activityName,
          "activityCount": -1, //活动数量 （ -1 为 无限量 ）
          "couponEnabled": values.couponEnabled === '1' ? 0 : 1, //能否使用优惠券 0 可以使用 1 不能使用
          "activityStatus": 1, //活动状态（0：正常 1：关闭）
          "activityType": values.activityType, //活动类型 （COUPONS 优惠卷 SHOP_GOODS 商城商品）
          activityDetailVos,
          activityLevel: values.activityLevel,
          detailExplain: values.detailExplain,
          detailImg: values.detailImg,
          startTime: values.startTime,
          endTime: values.endTime,
          timeType: values.timeType,
        }
      }

      if (values.activityType === 'COUPONS') {
        params["activityWay"] = values.activityWay //活动方式（ REGISTERED 注册 ONSALE 特价）
      }
      if (['FULL_REDUCTION'].includes(values.activityType)) {
        // console.log(values);
        params["activityBlacklists"] = values.blackGoods.map(item => {
          return { goodsId: item.goodsId }
        }) //活动方式（ REGISTERED 注册 ONSALE 特价）
      }
      if (['SHOP_GOODS', 'NEW_COME'].includes(values.activityType)) {
        apiActivitySkuFloorPriceVerify(params).then(res => {
          if (res.code === 0 && res.data && Array.isArray(res.data) && res.data.length > 0) {
            confirm({
              title: '提示',
              width: 800,
              icon: <ExclamationCircleFilled />,
              okText: '继续提交',
              cancelText: "返回",
              content: <div>
                {res.data.map((item, index) => <p key={index}>{item.tip}</p>)}
              </div>,
              onOk() {
                resolve(true);
                return submitData({ ...params, floorPrice: true })
              },
              onCancel() {
                resolve(true);
              },
            });
          } else {
            // resolve(true);
            submitData({ ...params })
          }
        })
      } else {
        // resolve(true);
        submitData({ ...params })
      }
    });
  }
  const checkGoodsSku = (rules, value) => {
    const { activityType } = formRef.current.getFieldsValue()
    value = PromotionsBox.current.state.goodsSku
    setGoodsSku(value)
    let flag = true, hasEmpty = true, hasJoin = true
    if (value) {
      value.forEach(item => {
        if (item[1].length === 0) {
          flag = false
          hasEmpty = false
          return
        }
        if (activityType === 'FULL_GIFT' && !item[2]) {
          flag = false
          item[3] = false
        }
        item[1].forEach(item2 => {
          let joinLen = item2.skuInfoVos.length
          item2.skuInfoVos.forEach(item3 => {
            // 验证是否存在参加活动的sku
            if (!item3.isJoinFlag) {
              joinLen -= 1
            }
            // 验证是否添加活动价格
            if ((!item3.hasOwnProperty('activityPrice') || item3.activityPrice === null || item3.activityPrice === '') && item3.isJoinFlag) {
              flag = false
              item3.flag = false
            } else {
              item3.flag = true

            }
            // 满赠活动类型验证商品别名是否添加
            if (activityType === 'FULL_GIFT' && (!item3.hasOwnProperty('aliasName') || !item3.aliasName) && item3.isJoinFlag) {

              flag = false
              item3.aliasFlag = false
            } else {
              item3.aliasFlag = true
            }
          })
          if (joinLen === 0) {
            hasJoin = false
            item2.hasJoinSku = false
          } else {
            item2.hasJoinSku = true

          }

        })
      })
      setGoodsSku(value)
      setGoodsFlag(flag && hasJoin)
      setCheckIng(true)
      // this.setState({
      //     goodsSku: value,
      //     goodsFlag: flag && hasJoin,
      //     checkIng: true
      // })
    }

    if ((value && value.length > 0 && flag)) {
      return Promise.resolve();

    } else {
      if (!hasEmpty) {
        return Promise.resolve();
      }
      if (!hasJoin) {
        return Promise.resolve();
      }
      if (!flag) {
        return Promise.resolve();
      }
      return Promise.reject(new Error('请添加活动商品'));
    }
  }
  const handleOk = async () => {
    setLoading(true)
    if (mode === "add") {
      console.log(saveData, { ...saveData });
      let res = await apiPlatformActivitySheetAdd({ ...saveData, repetitionPrice: true, })
      if (res.code === 0 && res.data) {
        setVisible(false)
        navigate(-1)
      }
      setVisible(false)
    } else {
      let res = await apiPlatformActivitySheetEdit({ ...saveData, repetitionPrice: true })
      if (res.code === 0 && res.data) {
        // this.props.history.goBack(-1)
        setVisible(false)
        navigate(-1)
      }
      setVisible(false)
    }
  }
  const handleCancel = () => {
    setVisible(false)
  }
  const getBlackGoods = (e) => {
    formRef.current.setFieldsValue({
      blackGoods: e
    })
  }
  return (
    <div className={'wrap-box'}>
      <GoBack title={title} />
      <div className={'wrap-box-content'}>
        <ProForm
          {...formItemLayout}
          readonly={mode === 'view'}
          formRef={formRef}
          layout={'horizontal'}
          submitter={{
            render: (props, doms) => {
              if (mode === 'view') {
                return null
              }
              return <Row>
                <Col span={22} offset={2}>
                  <Space>{doms}</Space>
                </Col>
              </Row>
            },
          }}
          // onValuesChange={(changeValues) => console.log(changeValues)}
          onFinish={async (values) => await onFinish(values)}
          onFinishFailed={(values) => {
            if (values.errorFields.length) {
              message.error('请完善数据')
            }
          }}
          params={{}}
          initialValues={{
            blackGoods: [],
            couponEnabled: '0',
            timeType: '0',
            activityTimeType: 1,
            activityType: '',
          }}
          request={async () => {
            // await waitTime(100);
            if (mode === "edit") {
              let res = await apiPlatformActivitySheetView({ activityId })
              if (res.code === 0) {
                let data = res.data
                let goodsSku = [], coupons = [], sights = []
                // 满减活动黑名单商品
                let blackGoodsKey = [], blackGoods = [], whiteGoodsKey = []
                if (['FULL_REDUCTION'].includes(data.activityType)) {
                  data.activityBlacklists.forEach(item => {
                    blackGoodsKey.push(item.goodsId)
                    blackGoods.push({ ...item.goodsInfo })
                  })
                }
                if (['COUPONS'].includes(data.activityType)) {
                  data.activityDetailVos.forEach(item => {
                    if (item.activityDetailId !== null) {
                      coupons.push({
                        ...item,
                        couponTitle: item.activityDetailName,
                        couponType: item.prizeType,
                        couponId: item.prizeId
                      })
                    }
                  })
                } else if (['SHOP_GOODS', 'NEW_COME', 'FULL_GIFT'].includes(data.activityType)) {
                  data.activityDetailVos.forEach(item => {
                    if (item.activityDetailId !== null) {
                      let goodsVos = []
                      item.activityGoodsVos.forEach(goods => {
                        if (goods.activityGoodsId !== null) {
                          whiteGoodsKey.push(goods.goodsId)
                          goodsVos.push({
                            activityDetailId: item.activityDetailId,
                            activityId: item.activityId,
                            activityPrice: goods.activityPrice,
                            goodsId: goods.goodsId,
                            storeId: goods.storeId,
                            activityGoodsId: goods.activityGoodsId,
                            storeName: goods.storeName,
                            goodsName: goods.goodsName,
                            Promotions: item.activityDetailName,
                            missGoods: goods.goodsStatus === '0' ? false : true,
                            hasJoinSku: true,
                            skuInfoVos: goods.activityGoodsSkuVos.map(sku => {
                              return {
                                flag: true,
                                missSku: sku.skuStatus === '0' ? false : true,
                                skuAttributes: JSON.parse(sku.skuAttributes),
                                "goodsId": sku.goodsId,
                                "goodsSkuId": sku.goodsSkuId,
                                "activityPrice": sku.missSku ? 0 : sku.activityGoodsSkuPrice === null ? null : (Number(sku.activityGoodsSkuPrice) / 100).toFixed(2),
                                skuOriginalPrice: Number(sku.skuOriginalPrice),
                                skuCurrentPrice: Number(sku.skuCurrentPrice),
                                activityGoodsSkuId: sku.activityGoodsSkuId,
                                activityGoodsId: sku.activityGoodsId,
                                aliasName: data.activityType === 'FULL_GIFT' ? sku.aliasName : '',
                                aliasFlag: true,
                                isJoinFlag: sku.skuEnabled
                              }
                            })
                          })
                        }
                      })
                      goodsSku.push([item.activityDetailName, goodsVos, item.thresholdPrice ? (Number(item.thresholdPrice) / 100).toFixed(2) : null, true, item.activityDetailId])
                    }
                  })
                } else if (['FULL_REDUCTION'].includes(data.activityType)) {
                  data.activityDetailVos.forEach(item => {
                    if (item.activityDetailId !== null) {
                      sights.push({
                        ...item,
                        thresholdPrice: (Number(item.thresholdPrice) / 100).toFixed(2),
                        discountPrice: (Number(item.discountPrice) / 100).toFixed(2),
                      })
                    }
                  })
                }
                setGoodsSku(goodsSku)
                let newData = {
                  activityName: data.activityName,
                  activityWay: data.activityWay,
                  coupons: coupons,
                  activityImg: data.activityImg,
                  blackGoods: blackGoods,
                  // activityLabelImg: data.activityLabelImg,
                  detailImg: data.detailImg,
                  activityTime: data.startTime ? [moment(data.startTime), moment(data.endTime)] : [],
                  activityLevel: data.activityLevel,
                  detailExplain: data.detailExplain,
                  activityType: data.activityType,
                  goodsSku: goodsSku,
                  sights: sights.map((item, index) => {
                    return {
                      fieldKey: index,
                      isListField: true,
                      key: index,
                      name: index,
                      thresholdPrice: item.thresholdPrice,
                      discountPrice: item.discountPrice,
                      activityDetailId: item.activityDetailId,
                    }
                  }),
                  couponEnabled: data.couponEnabled === 0 ? "1" : "0",
                  timeType: data.timeType,
                  commissionRate: data.commissionRate,
                  enableCommissionRate: data.enableCommissionRate
                }
                setCouponsCopy(coupons)
                setSights(sights)
                return newData
              }
            } else {
              return {}
            }
          }}
          onValuesChange={(values) => {
            console.log(values);
            if ("activityType" in values) {
              if (["SHOP_GOODS","NEW_COME"].includes(values.activityType)) {
                formRef.current.setFieldsValue({ enableCommissionRate: 0 })
                formRef.current.resetFields(['commissionRate'])
              }
            }
          }}
        >
          <ProFormText
            width={'md'}
            name={'activityName'}
            label="活动名称"
            fieldProps={{
              showCount: true,
              maxLength: 50
            }}
            rules={[
              {
                required: true,
              }
            ]}
          />
          <ProFormSelect
            width={'md'}
            name="activityType"
            disabled={mode === "edit"}
            label="活动类型"
            fieldProps={{
              fieldNames: {
                label: "platformSetShowValue",
                value: "platformSetUseValue"
              }
            }}
            request={async () => {
              let res = await apiGetActivityConfig({ platformSetKey: 'ACTIVITY_TYPE' });
              if (res.code === 0) {
                return res.data
              }
              else return []
            }}
            rules={[{ required: true, message: '请选择活动类型' }]}
          />
          <ProFormSwitch
            width={'md'}
            name="timeType"
            label="定时任务"
            formItemProps={{
              getValueProps: value => ({ checked: value === "1", value }),
              getValueFromEvent: (e) => (e ? "1" : "0"),
            }}
            rules={[
              {
                required: true,
                message: '请选择是否开启定时任务!',
              },
            ]}
          />
          <ProFormDependency name={['timeType']}>
            {({ timeType }) => {
              if (timeType === '1') {
                return <ProFormDateTimeRangePicker
                  width="md"
                  name={'activityTime'}
                  label="活动时间"
                  showTime
                  fieldProps={{
                    disabledDate: disabledDate,
                    // format: "YYYY-MM-DD HH:mm"
                    // format: (value) => value.format(format),
                  }}
                  transform={(values) => {
                    return {
                      startTime: values ? values[0] : undefined,
                      endTime: values ? values[1] : undefined,
                    };
                  }}
                  rules={[
                    {
                      required: true,
                      message: '请选择活动时间'
                    }
                  ]}
                />
              }
            }}
          </ProFormDependency>
          <ProFormDependency name={['activityType']}>
            {({ activityType }) => {
              if (['SHOP_GOODS', 'NEW_COME', 'FULL_GIFT', ''].includes(activityType)) {
                return <ProForm.Item
                  label="商品"
                  name="goodsSku"
                  trigger="onValuesChange"
                  rules={[
                    {
                      required: true,
                      validator: checkGoodsSku
                    }
                  ]}
                >
                  <Goods
                    blackGoodsKey={blackGoodsKey}
                    checkIng={checkIng}
                    mode={'add'}
                    ref={PromotionsBox}
                    isProprietary={isProprietary}
                    activityType={activityType}
                    goodsSku={goodsSku}
                    addGoods={addGoods} />
                </ProForm.Item>
              }
            }}
          </ProFormDependency>
          <ProFormDependency name={['activityType']}>
            {({ activityType }) => {
              if (['FULL_REDUCTION'].includes(activityType)) {
                return <ProFormList
                  name="sights"
                  label="满减"
                  copyIconProps={false}
                  initialValue={[]}
                  rules={[
                    {
                      required: true,
                      message: '请添加满减规则'
                    }
                  ]}
                >
                  <ProFormGroup key="group"
                    rowProps={
                      {
                        gutter: 5
                      }
                    } >
                    <ProFormMoney
                      name="thresholdPrice"
                      min={0}
                      rules={[
                        {
                          required: true,
                          message: '请填写金额'
                        }
                      ]}
                      fieldProps={{
                        precision: 2,
                        placeholder: '满金额',
                      }}
                    />
                    <ProFormText value={'元减'} readonly />
                    <ProFormDigit
                      name="discountPrice"
                      min={0}
                      rules={[
                        {
                          required: true,
                          message: '请填写金额'
                        }
                      ]}
                      fieldProps={{
                        precision: 2,
                        placeholder: '减金额',
                      }}
                    />
                    <ProFormText value={'元'} readonly />
                  </ProFormGroup>
                </ProFormList>
              }
            }}
          </ProFormDependency>
          <ProFormDependency name={['activityType']}>
            {({ activityType }) => {
              if (['SHOP_GOODS', ''].includes(activityType)) {
                return <ProFormSwitch
                  width={'md'}
                  name="couponEnabled"
                  label="是否用券"
                  formItemProps={{
                    getValueProps: value => ({ checked: value === "1", value }),
                    getValueFromEvent: (e) => (e ? "1" : "0"),
                  }}
                  rules={[
                    {
                      required: true,
                      message: '请选择是否用券!',
                    },
                  ]}
                />
              }
            }}
          </ProFormDependency>
          <ProFormDependency name={['activityType']}>
            {({ activityType }) => {
              if (['FULL_REDUCTION'].includes(activityType)) {
                return <ProForm.Item
                  label="不可参与商品"
                  name="blackGoods"
                  trigger="onValuesChange"
                >
                  <NoCanJoinGood ref={blackGoodsRef} onValuesChange={getBlackGoods} mode={mode} isProprietary={isProprietary}></NoCanJoinGood>
                </ProForm.Item>
              }
            }}
          </ProFormDependency>
          <TheUpload
            label="主图横幅"
            name="activityImg"
            len={1}
          />
          <TheUpload
            label="详情图片"
            name="detailImg"
            len={1}
          />
          <ProFormDependency name={['activityType']}>
            {({ activityType }) => {
              if (['SHOP_GOODS'].includes(activityType)) {
                return <ProFormSwitch
                  width={'md'}
                  name="enableCommissionRate"
                  label="高佣活动"
                  formItemProps={{
                    getValueProps: value => ({ checked: value === 1, value }),
                    getValueFromEvent: (e) => (e ? 1 : 0),
                  }}
                  rules={[
                    {
                      required: true,
                      message: '请选择是否开启高佣活动',
                    },
                  ]}
                />
              }
            }}
          </ProFormDependency>
          <ProFormDependency name={['activityType', 'enableCommissionRate']}>
            {({ activityType, enableCommissionRate }) => {
              if (['SHOP_GOODS', 'NEW_COME'].includes(activityType)) {
                return <ProFormDigit
                  width={'md'}
                  name="commissionRate"
                  min={0}
                  label='高级分享官分佣比例'
                  rules={[
                    {
                      required: true,
                      message: '请填写高级分享官分佣比例'
                    }
                  ]}
                  fieldProps={{
                    precision: 0,
                    placeholder: '请输入分佣比例 ',
                    addonAfter: '%',
                    min:0,
                    max:100
                  }}
                />
              }
            }}
          </ProFormDependency>
        </ProForm>
        <Modal
          open={visible}
          title="提示"
          onOk={() => handleOk()}
          onCancel={() => handleCancel()}
          okButtonProps={{
            loading: loading
          }}
          width="60%"
        >
          {clashData &&
            <List dataSource={clashData}
              renderItem={item => {
                return <List.Item>
                  <div>
                    商品id {item.goodsId}+{item.materialName}已存在一个{item.activityStatus === 0 ? '开启' : '关闭'}的活动【{item.activityName}】中！
                  </div>
                </List.Item>
              }}
            />
          }
          <br />
          <div>
            同一个时间段商品只能存在一个价格、优惠券使用状态，是否选择覆盖以上商品在其他特惠活动/新人活动中的价格、优惠券使用状态？
          </div>
        </Modal>
      </div>
    </div>
  )
};
export default Add;
